from PIL import Image
import io

# I don't know what Python version you're using, so I'll try using Python 3 first
try:
	import urllib.request as urllib
except ImportError:
	# You are using Python 2 it turns out
	import urllib

def my_func(filename, ext):
	# Get the image from the URL
	im = Image.open(urllib.urlopen(filename))

	fp = io.BytesIO()
	format = Image.registered_extensions()['.'+ext]
	im.save(fp, format)
	return fp.getvalue()

jpg_bin = my_func("http://p1.pstatp.com/list/300x196/pgc-image/152923179745640a81b1fdc.webp", "jpg")